﻿using System;
using System.Web.Mvc;
using ProjetoComperio.BusinessLogicLayer;
using ProjetoComperio.DataLayer.Entities;
using ProjetoComperio.Framework.Web.Security.UrlEncrypt;
using ProjetoComperio.SystemFramework.Web;

namespace ProjetoComperio.Presentation.Web.Controllers
{
    public class SubjectController : ComperioController
    {

        private SubjectBLL _subjectBLL;


        public SubjectController()
        {
            _subjectBLL = new SubjectBLL();
        }



        public ActionResult Index()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult Create(String id)
        {
            Session["contributionID"] = id;

            return View();
        }

        public ActionResult Remove(String id)
        {
            _subjectBLL.Remove(Convert.ToInt32(id));

            return View();
        }


        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(Subject subject)
        {
            if (!ModelState.IsValid)
                return View();

            subject.CreatedDate = DateTime.Now;
            subject.UserName = "User";
            subject.ContributionID = Convert.ToInt32(URLEncrypt.DecryptFromString(Session["contributionID"].ToString()));

            _subjectBLL.Create(subject);

            return Redirect("~/Project/Edit/" + Session["id"]);
        }
    }
}
